package com.luych.toolbox.docker.service.sdk.network.model;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

public class DockerNetworksResult extends ArrayList<DockerNetworksResult.Network> {

    public static class Network {

        @JsonProperty("IPAM")
        private IPAM ipam;

        @JsonProperty("Options")
        private Map<String, String> options;

        @JsonProperty("Scope")
        private String scope;

        @JsonProperty("Internal")
        private Boolean internal;

        @JsonProperty("Driver")
        private String driver;

        @JsonProperty("Ingress")
        private Boolean ingress;

        @JsonProperty("Id")
        private String id;

        @JsonProperty("Attachable")
        private Boolean attachable;

        @JsonProperty("EnableIPv6")
        private Boolean enableIPv6;

        @JsonProperty("Name")
        private String name;

        @JsonProperty("Created")
        private String created;

        @JsonProperty("Labels")
        private Map<String, String> labels;

        public IPAM getIpam() {
            return ipam;
        }

        public void setIpam(IPAM ipam) {
            this.ipam = ipam;
        }

        public Map<String, String> getOptions() {
            return options;
        }

        public void setOptions(Map<String, String> options) {
            this.options = options;
        }

        public String getScope() {
            return scope;
        }

        public void setScope(String scope) {
            this.scope = scope;
        }

        public Boolean getInternal() {
            return internal;
        }

        public void setInternal(Boolean internal) {
            this.internal = internal;
        }

        public String getDriver() {
            return driver;
        }

        public void setDriver(String driver) {
            this.driver = driver;
        }

        public Boolean getIngress() {
            return ingress;
        }

        public void setIngress(Boolean ingress) {
            this.ingress = ingress;
        }

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public Boolean getAttachable() {
            return attachable;
        }

        public void setAttachable(Boolean attachable) {
            this.attachable = attachable;
        }

        public Boolean getEnableIPv6() {
            return enableIPv6;
        }

        public void setEnableIPv6(Boolean enableIPv6) {
            this.enableIPv6 = enableIPv6;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getCreated() {
            return created;
        }

        public Date getCreatedDate() {
            if (created == null) return null;
            ZonedDateTime zonedDateTime = ZonedDateTime.parse(created, DateTimeFormatter.ISO_DATE_TIME);
            return Date.from(zonedDateTime.toInstant());
        }

        public void setCreated(String created) {
            this.created = created;
        }

        public Map<String, String> getLabels() {
            return labels;
        }

        public void setLabels(Map<String, String> labels) {
            this.labels = labels;
        }

        public static class IPAM {

            @JsonProperty("Config")
            private List<Config> config;

            @JsonProperty("Driver")
            private String driver;

            public List<Config> getConfig() {
                return config;
            }

            public void setConfig(List<Config> config) {
                this.config = config;
            }

            public String getDriver() {
                return driver;
            }

            public void setDriver(String driver) {
                this.driver = driver;
            }

            public static class Config {

                @JsonProperty("Subnet")
                private String subnet;

                @JsonProperty("IPRange")
                private String ipRange;

                @JsonProperty("Gateway")
                private String gateway;

                @JsonProperty("AuxAddress")
                private String auxAddress;

                public String getSubnet() {
                    return subnet;
                }

                public void setSubnet(String subnet) {
                    this.subnet = subnet;
                }

                public String getIpRange() {
                    return ipRange;
                }

                public void setIpRange(String ipRange) {
                    this.ipRange = ipRange;
                }

                public String getGateway() {
                    return gateway;
                }

                public void setGateway(String gateway) {
                    this.gateway = gateway;
                }

                public String getAuxAddress() {
                    return auxAddress;
                }

                public void setAuxAddress(String auxAddress) {
                    this.auxAddress = auxAddress;
                }
            }
        }
    }
}
